package com.wms_backend.security;

import com.wms_backend.dao.UserDao;
import com.wms_backend.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class UserDetailsServiceImpl implements UserDetailsService {

  @Autowired
  private UserDao userDao;

  @Override
  public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
    User user = userDao.findByUserId(username)
        .orElseThrow(() -> new UsernameNotFoundException("User Not Found with user id: " + username));

    return UserDetailsImpl.build(user);
  }

}
